package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.PackageService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
public class PackageController {
    @Autowired
    private PackageService packageService;
    //新增套餐
    @PostMapping
    public Result addPackage(@RequestBody SetmealDTO setmealDTO){
        packageService.addPackage(setmealDTO);
        return Result.success();
    }



    //根据分类id查询菜品
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result list(Long categoryId){//这里的参数记得要是categoryId
        log.info("根据分类id查询菜品：{}",categoryId);
        List<Dish> list=packageService.getByCategoryId(categoryId);
        return Result.success(list);
    }
    //套餐分页查询
    @GetMapping("/page")
    public Result<PageResult> selectPage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = packageService.selectPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    //根据id删除分类
    @DeleteMapping
    public Result deletePage(@RequestParam List<Long> ids){
        packageService.deletePage(ids);
        return Result.success();
    }
    //根据id查询套餐
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
        SetmealVO setmealVO = packageService.selectById(id);
        return Result.success(setmealVO);
    }
    //修改菜品
    @PutMapping
    public Result putSetmeal(@RequestBody SetmealDTO setmealDTO){
        packageService.putSetmeal(setmealDTO);
        return Result.success();
    }

}
